namespace CISLib
{
    using System;
    using System.Data;
    using System.Xml;

    public class ManageSystemConfig
    {
        public static string GetSystemConfig(string configKey)
        {
            string result;
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(configKey, "ConfigKey", SqlDbType.VarChar);
            string strSQL = "select ConfigValue FROM  TB_SysConfig where ConfigKey = @ConfigKey";
            MyDB.DBSetSelect(strSQL);
            try
            {
                result = MyDB.DBExecuteScalar().ToString();
            }
            catch (Exception)
            {
                return "";
            }
            MyDB.DBClose();
            return result;
        }

        public static string GetSystemSetLanguage(string formName, string controlName, string language, string path)
        {
            XmlDocument doc = new XmlDocument();
            string strResult = "";
            XmlTextReader reader = null;
            reader = new XmlTextReader(path);
        Label_0086:
            while (reader.Read())
            {
                if (reader.GetAttribute("id") == formName)
                {
                    XmlNode tmpNode = doc.ReadNode(reader);
                    for (int i = 0; i < tmpNode.ChildNodes.Count; i++)
                    {
                        if (tmpNode.ChildNodes[i].Name == controlName)
                        {
                            strResult = tmpNode.ChildNodes[i].Attributes[language].Value;
                            goto Label_0086;
                        }
                    }
                }
            }
            return strResult;
        }

        public static bool IsThisCustomerMaster(Guid userId, Guid CustomerId)
        {
            return ManageCustomer.GetCustomerBasicInfoViaId(CustomerId).UserId.Equals(userId);
        }

        public static void UpdateSystemConfig(string configKey, string configValue)
        {
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(configKey, "ConfigKey", SqlDbType.VarChar);
            MyDB.AddParameters(configValue, "ConfigValue", SqlDbType.VarChar);
            string strSQL = "Update TB_SysConfig set ConfigValue = @ConfigValue where ConfigKey = @ConfigKey";
            MyDB.DBSetSelect(strSQL);
            MyDB.DBExcuteNonQuery();
            MyDB.DBClose();
        }
    }
}

